package DMSXL._2024.TX;

import Hot100.twoSearch.findMin;

import java.sql.SQLOutput;
import java.util.Arrays;
import java.util.Map;

public class findMinArrowShots {
    public static void main(String[] args) {
        int[][] points = {{-2147483646,-2147483645},{2147483646,2147483647}};
        System.out.println(new findMinArrowShots().findMinArrowShots(points));
    }
    public int findMinArrowShots(int[][] points) {
        if(points.length == 1){
            return 1;
        }
        //先对points数组排序

        Arrays.sort(points,(a,b) -> Integer.compare(a[0],b[0]));


        int left = points[0][0];
        int right = points[0][1];
        int result = 0;
        for (int i = 1; i < points.length; i++) {
            //如果有交集，则只需要一箭
            if(points[i][0] <= right){
                left = points[i][0];
                right = Math.min(right,points[i][1]);
            }else {
                result ++;
                left = points[i][0];
                right = points[i][1];

            }
            if(i == points.length - 1){
                result++;
            }

        }
        return result;
    }
}
